package com.hjx.controller;

import com.hjx.entity.SysApply;
import com.hjx.logging.LogAnnotation;
import com.hjx.response.AjaxResponse;
import com.hjx.response.ResponseType;
import com.hjx.service.SysApplyService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>Title:</p>
 * <p>Description:</p>
 *
 * @author hjx
 * @date 2020/6/10 - 17:34
 */
@RestController
@RequestMapping("apply")
public class SysApplyController {
    @Resource
    SysApplyService sysApplyService;

    @LogAnnotation
    @GetMapping("/findAll")
    public AjaxResponse findAllApply() {
//        final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
//         User principal = (User)authentication.getPrincipal();
//        System.out.println(principal);
        List<SysApply> applies = sysApplyService.findAll();
        if (applies != null && applies.size() != 0) {
            return new AjaxResponse(ResponseType.QUERY_SUCCESS, applies);
        }
        return new AjaxResponse(ResponseType.QUERY_FAILED);
    }

    @LogAnnotation
    @PostMapping("/findBy")
    public AjaxResponse findBy(@RequestBody SysApply sysApply) {
        List<SysApply> applies = sysApplyService.findBy(sysApply);
        if (applies != null && applies.size() != 0) {
            return new AjaxResponse(ResponseType.QUERY_SUCCESS, applies);
        }
        return new AjaxResponse(ResponseType.QUERY_FAILED);
    }

    @LogAnnotation
    @PostMapping("/updateStatus")
    public AjaxResponse updateStatus(@RequestBody Map<String, Object> map) {
        boolean result = sysApplyService.updateStatus(map);
        if (result) {
            return new AjaxResponse(ResponseType.OPERATION_SUCCESS);
        }
        return new AjaxResponse(ResponseType.OPERATION_FAILED);
    }

}
